package main

import (
	"fmt"
	"math/rand"
	"sort"
)

/**
 * @author: guangcheng
 * @date:   2020/11/24 11:46
 * @version  V1.0
 * @description:
 *
 */
type Fighter struct {
	Name  string
	Power float64
}

type FighterSlice []Fighter

func (f FighterSlice) Len() int {
	return len(f)
}
func (f FighterSlice) Less(i, j int) bool {
	return f[i].Power > f[j].Power
}
func (f FighterSlice) Swap(i, j int) {
	f[i], f[j] = f[j], f[i]
}

func main() {
	var fs FighterSlice
	for i := 0; i < 10; i++ {
		fighter := Fighter{
			Name:  fmt.Sprintf("Fighter-%d", i),
			Power: float64(rand.Intn(1000000)),
		}
		fs = append(fs, fighter)
	}

	for i := 0; i < 10; i++ {
		fmt.Println(fs[i])
	}
	fmt.Println("------------------排序后-----------------------")

	sort.Sort(fs)
	for i := 0; i < 10; i++ {
		fmt.Println(fs[i])
	}
}
